<template>
	<view class="h-full">

		<template v-if="userInfo">
			<web-view v-if="url" style="height: 100%;width: 100%;" :src="url"></web-view>
			<view v-else class="flex-center h-full">
				当前工地没绑定摄像头
			</view>
		</template>

		<view v-else class="flex-center h-full">
			<navigator class="user_login_btn" url="/pages/user/login">去登录</navigator>
		</view>
	</view>
</template>

<script>
	import {
		logout,
		userinfo,
		getAd
	} from "@/api/base.js"
	import {
		getServiceList
	} from "@/api/project.js"
	let that;

	export default {
		data() {
			return {
				userInfo: "", //用户信息	
				projectId: "", //
				webhost: "https://mkh5.hsszschina.com",
				// webhost: "http://localhost:5173/",
			}
		},
		onShow() {
			that = this
			this.getUserInfo();
		},
		computed: {
			url: function() {
				let url = this.webhost + "?run_env=wxmp&"
				const isAdmin = this.userInfo && this.userInfo.username === "19925233366";
				if (isAdmin) {
					return `${url}auth=1`
				} else if (this.projectId) {
					return `${url}projectId=${projectId}`
				}
			}
		},
		methods: {
			getList() {
				let params = {
					page: 1,
					size: 20,
					from: "weminicut"
				};
				that.houseList = []
				getServiceList(params).then((res) => {
					const list = res.data.list || []
					if (list.length > 0) {
						that.projectId = list[0]["customer"]["MKId"];
					}
				})
			},
			getUserInfo() {
				let that = this
				that.userInfo = ""
				userinfo().then((res) => {
					if (res.data && res.data.wechat && res.data.id) {
						that.userInfo = res.data
					} else {
						that.userInfo = uni.getStorageSync("userinfo")
					}
				})
			},
		},
	}
</script>


<style>
	@import '@/common/uni-nvue.css';

	.user_login_btn {
		background-color: #007AFF;
		border-radius: 50px;
		height: 52px;
		line-height: 52px;
		width: 200px;
		text-align: center;
		color: #fff;
		margin: 40rpx 0 0 30rpx;
	}

	.flex-center {
		display: flex;
		align-items: center;
		justify-content: center
	}
</style>